package com.lzh.dlykserver.config.convert;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.lzh.dlykserver.DlykServerApplication;
import com.lzh.dlykserver.entity.TProduct;
import com.lzh.dlykserver.result.DicEnum;

import java.util.List;

/**
 * 意向产品转换器
 */
public class IntentionProductConverter implements Converter<Integer> {
    @Override
    public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        //cellData是excel中读取的数据
        String cellAppellationName = cellData.getStringValue();

        List<TProduct> tDicValueList = (List<TProduct>) DlykServerApplication.cacheMap.get(DicEnum.PRODUCT.getCode());

        for (TProduct tProduct : tDicValueList) {
            Integer id = tProduct.getId();
            String name = tProduct.getName();

            if (cellAppellationName.equals(name)) {

                return id;
            }
        }

        return -1;
    }
}
